import axios from 'axios';

const instance = axios.create({
    baseURL: 'http://localhost:8080',
    timeout: 5000,
    withCredentials: true
});

// 请求拦截器
instance.interceptors.request.use(
    config => {
        // 在这里可以添加token等认证信息
        return config;
    },
    error => {
        return Promise.reject(error);
    }
);

// 响应拦截器
instance.interceptors.response.use(
    response => {
        return response.data;
    },
    error => {
        return Promise.reject(error);
    }
);

// 用户相关的API接口
export const userApi = {
    login: (data: any) => {
        return instance.post('/api/user/login', data);
    },
    register: (data: any) => {
        return instance.post('/api/user/register', data);
    },
    getUserInfo: () => {
        return instance.get('/api/user/info');
    }
};